﻿using UnityEngine;
using System.Collections;
using strange.extensions.mediation.impl;
using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using System;

namespace NormalBattleIoc
{

    public class TurnBattleEventMediator : Mediator
    {
        [Inject]
        public TurnBattleEventView view { get; set; }

        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        /// <summary>
        /// 这里做初始化的操作，相当于start
        /// </summary>
        public override void OnRegister()
        {
             view.dispatcher.AddListener(BattleUIEvent.OPEN_Person_OperationPanel, OnOpenPerson_OperationPanel);
            view.dispatcher.AddListener(BattleUIEvent.OPEN_Tank_OperationPanel, OnOpenTank_OperationPanel);

            view.dispatcher.AddListener(BattleUIEvent.Close_All_Panel, OnCloseAll_Panel);


            view.dispatcher.AddListener(BattleUIEvent.ShowWinPanel, OnShowWinPanel);

            view.dispatcher.AddListener(BattleUIEvent.UpdatePlayerHp , OnUpdatePlayerHp );

        }

        private void OnOpenTank_OperationPanel(IEvent payload)
        {
            dispatcher.Dispatch(BattleUIEvent.OPEN_Tank_OperationPanel);
        }

        private void OnUpdatePlayerHp(IEvent payload)
        {
            dispatcher.Dispatch(BattleUIEvent.UpdatePlayerHp );
        }

        private void OnShowWinPanel(IEvent payload)
        {
            dispatcher.Dispatch(BattleUIEvent.ShowWinPanel);
        }

        public void OnOpenPerson_OperationPanel()
        {
            dispatcher.Dispatch(BattleUIEvent.OPEN_Person_OperationPanel);
        }

        public void OnCloseAll_Panel()
        {
            dispatcher.Dispatch(BattleUIEvent.Close_All_Panel);
        }


    }
}
